package com.ayic.garbagerecycle.service.impl;

import com.ayic.garbagerecycle.mapper.RegisterMapper;
import com.ayic.garbagerecycle.pojo.Result;
import com.ayic.garbagerecycle.pojo.User;
import com.ayic.garbagerecycle.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterServiceImplement implements RegisterService {
    @Autowired
    private RegisterMapper registerMapper;

    @Override
    public Result register(User user) {
        // 检查用户名是否已存在
        if (registerMapper.checkUsername(user.getUsername()) > 0) {
            return Result.error("用户名已存在");
        }

        // 对密码进行MD5加密
        //String encryptedPassword = DigestUtils.md5DigestAsHex(password.getBytes());

        // 插入新用户
        int rows = registerMapper.insertUser(user);
        if (rows > 0) {
            return Result.success();
        } else {
            return Result.error("注册失败");
        }
    }
}
